package com.sinosoft.dsp.component.bpm.viewbean.activity.part;

import org.jbpm.xsdobject.Process;

import com.sinosoft.dsp.component.bpm.service.core.BpmSelectItemsService;
import com.sinosoft.dsp.component.bpm.util.ProcessParse;
import com.sinosoft.dsp.component.bpm.viewbean.BpmJpdlDefineViewBean;
import com.sinosoft.dsp.component.bpm.viewbean.activity.IBpmActivityPartEditViewBean;
import com.sinosoft.dsp.system.core.exception.SinoException;
import com.sinosoft.dsp.system.to.IGenericTO;
import com.sinosoft.dsp.system.to.attribute.Attribute;
import com.sinosoft.dsp.system.to.helper.ToHelper;
import com.sinosoft.dsp.system.utils.Const;

public class BpmActivityDecisionBaseViewBean extends
		BpmActivityCommonBaseViewBean implements IBpmActivityPartEditViewBean {

	// 表达式
	public static final String FIELD_EXPR = "expr";

	// 表达式语言
	public static final String FIELD_LANG = "lang";

	// 委托判断
	public static final String FIELD_HANDLER = "handler";

	@Override
	public void init(IGenericTO tos) throws SinoException {
		super.init(tos);

		// 活动对象
		Attribute<?> name = ToHelper.getContentAttriubteByName(tos,
				BPM_NODE_NAME);
		String nameStr = name.convertToString();

		BpmJpdlDefineViewBean pvb = (BpmJpdlDefineViewBean) this.getParent()
				.getParent();
		org.jbpm.xsdobject.Process process = pvb.getProcess();
		Process.Decision obj = (Process.Decision) ProcessParse.getActivity(
				process, nameStr);

		this.addField(FIELD_EXPR, Const.NVL(obj.getExpr(), ""));
		this.addField(FIELD_LANG, Const.NVL(obj.getLang(),
				BpmSelectItemsService.SELECT_ITEM_LANG_DEFAULT));
		// TODO
		// this.addField(FIELD_EXPR, Const.NVL(obj.getHandler(), ""));
	}

}
